import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;


public class Simulator {
	UserSimulator user;
	Baxterpump bpump;
	
	Simulator() {
		user = new UserSimulator();
		bpump = new Baxterpump(user);
	}
	
	public static void main(String[] args) {
		
		int invalid_input = 0;
		int invalid_range = 0;
		int tot_runs = 0;
		int pres_gen = 0;
		Simulator simulate = new Simulator();
		boolean done = simulate.user.nextInput();
		while(!done) {
			tot_runs++;
			boolean valid = simulate.bpump.run();
			if(valid) {
				simulate.bpump.gen_pres();
				pres_gen++;
			}
			else {
				invalid_input++;
			}
			done = simulate.user.nextInput();
			if(done)
			{
				System.out.println("Simulation done");
			}
			simulate.bpump.init();
		}
		try {
			String name = new String("/home/sid/prescription/" + "stats");
		    BufferedWriter out = new BufferedWriter(new FileWriter(name));
		    out.write("Prescription discarded due to Invalid Inputs: " + invalid_input);
		    out.newLine();
		    out.write("Prescription discarded due to Invalid Range: " + invalid_range);
		    out.newLine();
		    out.write("Total Prescriptions Discarded: " + (invalid_range + invalid_input));
		    out.newLine();
		    out.write("Total Prescriptions generated: " + pres_gen);
		    out.newLine();
		    out.write("Total Simulation runs: " + tot_runs);
		    out.newLine();
		    out.close();
		} catch (IOException e) {
		}
	}
}
